package com.tedu._08security.base.config;

import com.tedu._08security.service.UserDetailService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class securityConfig {
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
                .authorizeHttpRequests(authorize-> authorize
                    .requestMatchers("/api/public/**")
                    .permitAll()
                    .anyRequest().authenticated()
                )
                .formLogin(form->form.permitAll());
        return httpSecurity.build();
    }

    @Bean
    public UserDetailService userDetailService(){
        return new UserDetailService();
    }
}
